package org.opensuse.bs.ui.model;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.eclipse.ui.progress.IElementCollector;


public abstract class BSModelElement implements IDeferredWorkbenchAdapter, IAdaptable {
	protected Object parent;
	protected String name;
	protected Object[] children;
	
	public BSModelElement(String name, Object parent) {
		this.parent = parent;
		this.name = name;
		children = new Object[0];
	}
	
	public String getName() {
		return name;
	}

	public abstract Object[]  fetchChildren(Object object, IProgressMonitor monitor);

	public void fetchDeferredChildren(Object o, IElementCollector collector, IProgressMonitor monitor) {
		collector.add(fetchChildren(o, monitor), monitor);
	}
	
	public ISchedulingRule getRule(Object object) {
		return null;
	}

	public boolean isContainer() {
		if(this instanceof RemoteFile)
			return false;
		return true;
	}

	public Object[] getChildren(Object o) {
		return fetchChildren(o, null);
	}
	
	public ImageDescriptor getImageDescriptor(Object object) {
		return null;
	}

	public Object getAdapter(Class adapter) {
		if ((adapter == IDeferredWorkbenchAdapter.class) && this instanceof IDeferredWorkbenchAdapter)
			return this;
		return null;
	}
	
	public String getLabel(Object o) {
		return name;
	}
}
